<template>
	<view class="container">
		<view>
			<image class="titleImage" v-if="subType==8" src="https://dnsverify.pfmoto.com/appstatic/master/masterMessage.jpg" mode="widthFix"></image>
			<image class="titleImage" v-else-if="subType==9" :src="data.context.split('**')[1]" mode="widthFix"></image>
			
			
			
			<image class="titleImage" v-else :src="data.img" mode="widthFix"></image>
			<view class="title">
				{{data.theme}}
			</view>
			<view class="time">
				{{data.createTime}}
			</view>

			<!-- <view class="msgtext">
					 {{data.context}}
			 </view> -->

			<view class="msgtext">
				<jyf-parser v-if="subType==9"  :html="data.context.split('**')[0]"></jyf-parser>
				<jyf-parser v-else :html="data.context"></jyf-parser>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	const util = require("../../utils/util.js");
	const network = require("../../manager/network-manager.js");
	const dialog = require("../../utils/dialog.js");
	// import wxParse from "../../../components/wxParse/wxParse";
	import parser from "@/components/jyf-parser/jyf-parser";

	export default {
		data() {
			return {
				data: {
					subType: ''
				},
			};
		},
		components: {
			"jyf-parser": parser
		},
		props: {},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			if (options && options.id) {
				this.data.id = options.id
				this.getInfoById(options.id);
				// this.update2Read(options.id,options.isType);
			}

			if (options.subType) {
				this.subType = options.subType
			}


			//更新已读
			if (options && options.id && (options.from == "message" || options.from == "notice")) {
				this.update2Read(options.id, options.isType, options.from);
			}
		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},

		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {
			readAll: function() {
				uni.navigateTo({
					url: 'systemMessage'

				});
			},
			update2Read: function(id, isType, from) {
				var that = this;
				var uri = app.globalData.config.interfaces.URL_SYS_SENDMSG_UPDATE_LEVCMSGUSERREADY;
				var params = {
					"id": id,
					"isType": isType
				};
				network.post(uri, params, 'json').then(res => {
					if (res.code == 200) {
						console.log("已读", JSON.stringify(res));
						if (from == 'message') {
							//回调上一个页面
							let pages = getCurrentPages();
							if (pages.length == 3) {
								let prePage = pages[pages.length - 2];
								let preprePage = pages[pages.length - 3]
								// #ifdef H5
								prePage.refresh(id);
								preprePage.refresh();
								// #endif
								// #ifdef APP-PLUS
								prePage.$vm.refresh(id);
								preprePage.$vm.refresh();
								// #endif
							}
						} else {
							let pages = getCurrentPages();
							let prePage = pages[pages.length - 2];
							// #ifdef H5
							prePage.refresh(id);
							// #endif
							// #ifdef APP-PLUS
							prePage.$vm.refresh(id);
							// #endif
						}
						util.syncBadge(getApp())
						// that.$util.prePage.refresh(id);
					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}

				}).catch(res => {
					uni.showToast({
						title: res.errMsg,
						duration: 3000,
						icon: 'none'
					})
					console.error(res);
				});
			},
			getInfoById: function(id) {
				var that = this;
				var uri = app.globalData.config.interfaces.URL_SYS_SENDMSG_GETLEVCMSGBYIDFRONT;
				var params = {
					"id": id
				};
				network.get(uri, params, 'form').then(res => {
					if (res.code == 200) {
						that.data = res.data
					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}

				}).catch(res => {
					uni.showToast({
						title: res.errMsg,
						duration: 3000,
						icon: 'none'
					})
					console.error(res);
				});
			}
		}
	};
</script>
<style lang='scss' scoped>
	@import "./systemMessage-detail.css";
</style>
